import { reqCategoryList, reqCetBannerList,reqCetFloorsList } from "@/api"

//home模块 小仓库模块
//准备actions一用于响应组件中的动作
const actions ={
    async categoryList({commit}){
        let result =await reqCategoryList()
        if(result.code==200){
            commit('CATEGORYLIST',result.data)
        }
    },
    //获取首页轮播图的数据
    async getBannerList({commit}){
        let result = await reqCetBannerList()
        if(result.code == 200){
            commit('GETBANNERLIST',result.data)
        }
    },
    //获取floor轮播图的数据
    async getFloorList({commit}){
        let result = await reqCetFloorsList()
        if(result.code == 200){
            commit('GETFLOORLIST',result.data)
        }
    },
};
//准备mutations.一用于操作数据(state)
const mutations ={
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList
    },
    GETBANNERLIST(state,getBannerList){
        state.getBannerList = getBannerList
    },
    GETFLOORLIST(state,getFloorList){
        state.getFloorList = getFloorList
    },
};
//准备state一用于存储数据
const state ={
    //起初数据为一个数组
    categoryList:[],
    getBannerList:[],
    getFloorList:[],
};
//getters:理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters = {}

//创建并暴露store
export default {
state,
mutations,
actions,
getters,
}